package com.atguigu.tingshu.live.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.live.service.LiveRoomService;
import com.atguigu.tingshu.model.live.LiveRoom;
import com.atguigu.tingshu.vo.live.LiveRoomVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

    @Autowired
    private LiveRoomService liveRoomService;

    @GuiGuLogin
    @Operation(summary = "获取当前直播间")
    @GetMapping("getCurrentLive")
    public Result<LiveRoom> getCurrentLive() {
        LiveRoom liveRoom = liveRoomService.getCurrentLive();
        return Result.ok(liveRoom);
    }

    @GuiGuLogin
    @Operation(summary = "创建直播间")
    @PostMapping("saveLiveRoom")
    public Result<LiveRoom> saveLiveRoom(@RequestBody LiveRoomVo liveRoomVo) {
        LiveRoom liveRoom = liveRoomService.saveLiveRoom(liveRoomVo);
        return Result.ok(liveRoom);
    }

    @Operation(summary = "根据id获取直播间")
    @GetMapping("getById/{id}")
    public Result<LiveRoom> getById(@PathVariable(value = "id") Long roomId) {
        LiveRoom liveRoom = liveRoomService.getById(roomId);
        return Result.ok(liveRoom);
    }

    // api/live/liveRoom/findLiveList
    @Operation(summary = "获取直播列表")
    @GetMapping("findLiveList")
    public Result<List<LiveRoom>> findLiveList() {
        List<LiveRoom> liveRoomList = liveRoomService.findLiveList();
        return Result.ok(liveRoomList);
    }
}

